<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item to="/">首页</el-breadcrumb-item>
    </el-breadcrumb>
    <el-row>
      <el-col :span="2" :offset="22">
        <el-tooltip class="refreshTable" content="点击刷新" placement="top" effect="dark">
          <el-button
            active-value="1"
            inactive-value="0"
            @click="refreshTable"
            class="refresh"
            type="success"
            icon="el-icon-refresh"
            circle
          ></el-button>
        </el-tooltip>
      </el-col>
    </el-row>

    <div id="myChart"></div>
  </div>
</template>

<script>
export default {
  inject: ["reload"],
  name: "Welcome",
  methods: {
    drawLine() {
      // 基于准备好的dom，初始化echarts实例
      let myChart = this.$echarts.init(document.getElementById("myChart"));
      // 绘制图表
      myChart.setOption(this.option);
    },
    getAllStatusAndCount() {
      this.$http
        .get("apply/queryAllStatusCount")
        .then(resp => {
          let { msg, code, data } = resp.data;
          if (code == 1) {
            this.option.series[0].data = data.applyStatusCountVOList;
            this.drawLine();
          }
          //  else if (code == 0) {
          //   this.$message.info(msg);
          // } else {
          //   this.$message.warning(msg);
          // }
        })
        .catch(resp => {
          console.log(resp);
        });
    },
    refreshTable() {
      this.reload();
    }
  },
  data() {
    return {
      option: {
        title: {
          text: "教室预定扁状统计图",
          left: "center"
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          left: "center",
          top: "bottom"
        },
        toolbox: {
          show: true,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            restore: { show: true },
            saveAsImage: { show: true }
          }
        },
        series: [
          {
            name: "数据统计",
            type: "pie",
            radius: [20, 140],
            center: ["50%", "50%"],
            roseType: "area",
            itemStyle: {
              borderRadius: 5
            },
            data: [
              { value: 30, name: "rose 1" },
              { value: 28, name: "rose 2" },
              { value: 26, name: "rose 3" },
              { value: 24, name: "rose 4" },
              { value: 22, name: "rose 5" },
              { value: 20, name: "rose 6" },
              { value: 18, name: "rose 7" },
              { value: 16, name: "rose 8" }
            ]
          }
        ]
      }
    };
  },
  created() {
    this.getAllStatusAndCount();
  },
  mounted() {}
};
</script>

<style lang="less" scoped>
.el-breadcrumb {
  margin-top: 10px;
}
#myChart {
  width: 600px;
  height: 400px;
  // border: 1px solid red;
  margin-left: 250px;
  margin-top: 30px;
}
.refreshTable {
  margin-left: 30px;
}
</style>